﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ARchGL.Platform.Core
{
    /// <summary>
    /// 公告 数据实体
    /// </summary>
    [Table("JN_" + nameof(Notices))]
    public class Notices : EntitySoftDeleteBase
    {
        /// <summary>
        /// 主键标识（巡检、自检等等）
        /// </summary>
        public Guid? PrimaryId { get; set; }
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }
        /// <summary>
        /// 正文
        /// </summary>
        public string Content { get; set; }
        /// <summary>
        /// 类型：1公告（这个位置固定不要改）、2系统通知、3巡检通知、4自检通知、5系统消息
        /// </summary>
        public int Type { get; set; }
        /// <summary>
        /// 状态：1显示、2隐藏
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public List<Guid> GetUserIdList(params string[] array)
        {
            var idList = new List<Guid>();
            foreach (var str in array)
            {
                var values = ((JArray)JsonConvert.DeserializeObject(str)).Values();
                foreach (var item in values)
                {
                    Guid.TryParse(item.ToString(), out var id);
                    idList.Add(id);
                }
            }
            return idList;
        }
    }

    /// <summary>
    /// 通知与用户关联表
    /// </summary>
    [Table("JN_" + nameof(NoticesUsers))]
    public class NoticesUsers : EntityCreatorUserIdBase
    {
        /// <summary>
        /// 接收用户标识
        /// </summary>
        public Guid UserId { get; set; }
        /// <summary>
        /// 公告标识
        /// </summary>
        public Guid NoticeId { get; set; }
        /// <summary>
        /// 状态：1已读、2未读
        /// </summary>
        public int Status { get; set; }
    }
}
